package com.ruoyi.tenants.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tenants.domain.Tenants;
import com.ruoyi.tenants.service.ITenantsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 租客管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/tenants/tenants")
public class TenantsController extends BaseController
{
    @Autowired
    private ITenantsService tenantsService;

    /**
     * 查询租客管理列表
     */
    @PreAuthorize("@ss.hasPermi('tenants:tenants:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tenants tenants)
    {
        startPage();
        List<Tenants> list = tenantsService.selectTenantsList(tenants);
        return getDataTable(list);
    }

    /**
     * 导出租客管理列表
     */
    @PreAuthorize("@ss.hasPermi('tenants:tenants:export')")
    @Log(title = "租客管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tenants tenants)
    {
        List<Tenants> list = tenantsService.selectTenantsList(tenants);
        ExcelUtil<Tenants> util = new ExcelUtil<Tenants>(Tenants.class);
        util.exportExcel(response, list, "租客管理数据");
    }

    /**
     * 获取租客管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('tenants:tenants:query')")
    @GetMapping(value = "/{tenantId}")
    public AjaxResult getInfo(@PathVariable("tenantId") Long tenantId)
    {
        return success(tenantsService.selectTenantsByTenantId(tenantId));
    }

    /**
     * 新增租客管理
     */
    @PreAuthorize("@ss.hasPermi('tenants:tenants:add')")
    @Log(title = "租客管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tenants tenants)
    {
        return toAjax(tenantsService.insertTenants(tenants));
    }

    /**
     * 修改租客管理
     */
    @PreAuthorize("@ss.hasPermi('tenants:tenants:edit')")
    @Log(title = "租客管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tenants tenants)
    {
        return toAjax(tenantsService.updateTenants(tenants));
    }

    /**
     * 删除租客管理
     */
    @PreAuthorize("@ss.hasPermi('tenants:tenants:remove')")
    @Log(title = "租客管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tenantIds}")
    public AjaxResult remove(@PathVariable Long[] tenantIds)
    {
        return toAjax(tenantsService.deleteTenantsByTenantIds(tenantIds));
    }
}
